<?php
namespace app\common\component\fruit;

use app\common\model\Fruit as FruitModel;

class FruitService {
	public function find($user_id) {
		$fruitModelGet = FruitModel::get(['user_id' => $user_id]);

		if(!$fruitModelGet) {
			$data['user_id'] = $user_id;
			
			return $this -> create($data);
		}

		return [
			'code' => 0,
			'data' => ['fruit' => $fruitModelGet]
		];;
	}

	public function create($data) {
		$fruitModel = FruitModel::create($data);

		if($fruitModel) {
			return [
				'code' => 0,
				'data' => ['fruit' => $fruitModel]
			];
		}

		return [
			'code' => -1,
			'message' => '创建失败,fruit'
		];
	}
}